package com.chenfan.mcn.component.dict;

import com.chenfan.mcn.clients.privilege.PrivilegeClient;
import com.chenfan.mcn.clients.privilege.SUser;
import com.chenfan.common.extension.context.SpringContextHolder;
import com.chenfan.common.extension.dict.DictTranslator;

import java.util.Objects;

/**
 * 登录用户-翻译成名称
 *
 * @author wulg
 * @date 2021-12-11
 **/
public class UserIdTranslator implements DictTranslator<Long, String> {

    @Override
    public String translate(Long userId) {
        PrivilegeClient privilegeClient = SpringContextHolder.getBean(PrivilegeClient.class);
        SUser sUser = privilegeClient.getUserById(userId).getObj();
        if(Objects.nonNull(sUser)) {
            return sUser.getUsername();
        }
        return userId.toString();
    }
}
